﻿@model LiteBlog.Models.PostCollectionModel
@using LiteBlog
@{
    this.Layout = "~/Views/Shared/_SiteLayout.cshtml";
}

<div id="posts" class="hidden" data-bind="css: { hidden: false }, foreach: posts">
    @Html.Partial("PostControl")
</div>

@section ScriptSection {
    <script type="text/javascript">
        $(function () {
            var postsVm = new PostsVm();
            @if (Model.Author != null)
            {
            <text>var author = $.parseJSON('@Html.Json(Model.Author)');
            if (author) {
                postsVm.setAuthor(author.Name, author.Url);
            }
            </text>
            }
            postsVm.page(@Model.Page);
            postsVm.pageCount(@Model.PageCount);
            postsVm.loadJson(@Html.Json(Model.PostCollection));
            var pageElem = document.getElementById("page");
            ko.cleanNode(pageElem);
            ko.applyBindings(postsVm, pageElem);
        });
    </script>
}

